/**
 * @param {number[]} nums
 * @return {string[]}
 */
var summaryRanges = function(nums) {
    const n = nums.length;
    const res = [];
    let j = 0;
    for (let i = 0; i < n; i++) {
        if (i == n - 1 || nums[i + 1] - nums[i] !== 1) {
            const sb = [];
            sb.push(nums[j]);
            if (j !== i) {
                sb.push("->");
                sb.push(nums[i]);
            }
            res.push(sb.join(''));
            j = i + 1;
        }
    }
    return res;
};